﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Enterprise.Model.Vote;
using Enterprise.Data.Vote;
using Enterprise.Infrastructure;
namespace Enterprise.Service.Vote
{
    /// <summary>
    /// 投票项服务
    /// </summary>
    public class VoteItemService
    {
        /// <summary>
        /// 列表 返回所有投票
        /// </summary>
        /// <returns></returns>
        public List<VoteItemEntity> VoteItemList(string voteId)
        {
            VoteItemData data = new VoteItemData();
            List<VoteItemEntity> list = data.VoteItemList(voteId);
            return list;
        }

        /// <summary>
        /// 操作 添加、修改、删除
        /// </summary>
        /// <param name="entity">经理信箱实体</param>
        public void VoteItemExecute(VoteItemEntity entity)
        {
            string cmd = string.Empty;
            switch (entity.DB_Option_Action)
            {
                case "Insert":
                    cmd = "Insert into VOTE_ITEM(VITEMID,VID,VITEMCODE,VITEMTITLE,VITEMREMARK) values(SEQ_VOTE_ITEM.nextval,'" + entity.VID + "','"+entity.VITEMCODE+"','" + entity.VITEMTITLE + "','" + entity.VITEMREMARK + "')";
                    break;
                case "Update":
                    cmd = "Update VOTE_ITEM set VITEMCODE='"+entity.VITEMCODE+"', VITEMTITLE='" + entity.VITEMTITLE + "',VITEMREMARK='" + entity.VITEMREMARK + "' where VITEMID=" + entity.VITEMID;
                    break;
                case "Delete":
                    cmd = "Delete from VOTE_ITEM where VITEMID='" + entity.VITEMID;
                    break;
            }
            if (!string.IsNullOrEmpty(cmd))
            {
                VoteItemExecuteBySql(cmd);
            }
        }

        /// <summary>
        /// 操作  
        /// </summary>
        /// <param name="cmd">sql语句</param>
        public void VoteItemExecuteBySql(string cmd)
        {
            VoteItemData data = new VoteItemData();
            data.Execute(cmd);
        }

        #region "静态方法"
        /// <summary>
        ///  获取选项序号
        /// </summary>
        /// <param name="vId">投票编号</param>
        /// <param name="itemId">投票项编号</param>
        /// <returns></returns>
        public static string GetVoteItemCode(string vId,int itemId)
        {
            VoteItemService viService = new VoteItemService();
            var query = viService.VoteItemList(vId).Where(p => p.VITEMID == itemId).FirstOrDefault();
            if (query != null)
            {
                return query.VITEMCODE;
            }
            return "";
        }
        #endregion

    }
}
